﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using MVlog.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Linq.Extensions;
using Abp.Authorization;
using MVlog.Authorization;

namespace MVlog.Application
{
        [AbpAuthorize(AppPermissions.Pages_Article)]
    public class ArticleAppService : AsyncCrudAppService<Article, ArticleDto, long, GetArticlesInput, CreateArticleInput, UpdateArticleInput>, IArticleAppService
    {
        public ArticleAppService(IRepository<Article, long> repository)
           : base(repository)
        {
        }

        public override async Task<PagedResultDto<ArticleDto>> GetAll(GetArticlesInput input)
        {

            var List =( await Repository.GetAllListAsync()).Where(o => o.CreatorUserId == AbpSession.UserId); 
            var count = List.Count();
            var returnList = ObjectMapper.Map<List< ArticleDto >>( List).AsQueryable().PageBy(input);
            return new PagedResultDto<ArticleDto>(count, returnList.ToList());

        }
    }
}
